

#include "ev_test.h"
#include "rtthread.h"
#include "ev_trans.h"

#ifdef RT_USING_FINSH
#include "shell.h"
#ifdef EV_BUILD_TEST

static void handler(void *parameter)
{
    int thread_id = (int)parameter;
    uint8_t seq = 0;
    ev_packet_t send_pkt;
    send_pkt.user = 0;
    send_pkt.seq = seq ++;
    send_pkt.cmd = 0xFF00;
    send_pkt.len = 16;
    rt_memset(send_pkt.data, (thread_id + 1) * 0x11, send_pkt.len);
    for (int i = 0; i < 100; i ++) {
        ev_trans_tx(&send_pkt);
    }
}

#define EV_TRANS_TEST_THREAD_NUM            10
#define EV_TRANS_TEST_THREAD_STACK_SIZE     512
#define EV_TRANS_TEST_THREAD_PRIO           4

ALIGN(8) static rt_uint8_t ev_trans_test_stack[EV_TRANS_TEST_THREAD_NUM][EV_TRANS_TEST_THREAD_STACK_SIZE];
static struct rt_thread ev_trans_test_thread[EV_TRANS_TEST_THREAD_NUM];
static void ev_trans_test(void)
{
    rt_err_t result;

    for (int i = 0; i < EV_TRANS_TEST_THREAD_NUM; i ++) {
        result = rt_thread_init(&ev_trans_test_thread[i], "test", &handler, (void *)i,
                                ev_trans_test_stack[i], sizeof(ev_trans_test_stack[i]),
                                EV_TRANS_TEST_THREAD_PRIO, 10);
        RT_ASSERT(result == RT_EOK);
        (void)result;
        rt_thread_startup(&ev_trans_test_thread[i]);
    }
}

MSH_CMD_EXPORT(ev_trans_test, ev trans test)

#endif /* EV_BUILD_TEST */

#endif /* RT_USING_FINSH */
